#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.


find_library(COGUTIL_LIBRARY
	NAMES cogutil
	PATH /usr/lib /usr/lib64 /usr/local/lib /usr/local/lib64)

INCLUDE (CheckIncludeFiles)

# The location of cogutil is variable. Find the right location.
find_path(COGUTIL_INCLUDE_DIR opencog/util/cogutil.h
	PATH /usr/include /usr/local/include
)

set(CMAKE_REQUIRED_INCLUDES ${COGUTIL_INCLUDE_DIR})
CHECK_INCLUDE_FILES (opencog/util/cogutil.h HAVE_COGUTIL_H)

if (COGUTIL_LIBRARY AND HAVE_COGUTIL_H)
	set(COGUTIL_FOUND TRUE)
	set(COGUTIL_VERSION 0)
	FILE(READ "${COGUTIL_INCLUDE_DIR}/opencog/util/cogutil.h" _CU_H_CONTENTS)
	STRING(REGEX MATCH
		"#define COGUTIL_VERSION_STRING[  ]+\"([0-9.]+)\""
		_MATCH "${_CU_H_CONTENTS}")
	SET(COGUTIL_VERSION ${CMAKE_MATCH_1})
endif (COGUTIL_LIBRARY AND HAVE_COGUTIL_H)

if ( COGUTIL_FOUND )
	message( STATUS "Found CogUtil version ${COGUTIL_VERSION} at ${COGUTIL_LIBRARY}")
else ( COGUTIL_FOUND )
	message( STATUS "CogUtil not found")
endif ( COGUTIL_FOUND )
